import base
import bluepy
import log
import macho
import gpcs

class MovementGPCS():
    __guid__ = 'gpcs.MovementGPCS'

    def NotifyUp(self, packet):
        if (boot.role == 'client'):
            sm.GetService('apertureClient').ProcessEntityMovementLump(packet.payload)
        elif (boot.role == 'server'):
            movementServer = sm.GetService('movementServer')
            movementServer.MovePlayer(session.charid, packet.payload)
            gpcs.CoreBroadcastStuff.__notifyRecvCount__['Movement'] += 1
            gpcs.CoreBroadcastStuff.__notifyRecvSourceCount__['Movement']['Client'] += 1
        else:
            log.LogError('Processed Movement on Invalid Node')



    def SendMovementToServer(self, data, nodeID):
        with bluepy.Timer('machoNet::SendMovementToServer'):
            self.ForwardNotifyDown(macho.MovementNotification(destination=macho.MachoAddress(service='movementServer', nodeID=nodeID), payload=data))



    def SendMovementByCharID(self, charid, data):
        with bluepy.Timer('machoNet::SendMovementByCharID'):
            callTimer = base.CallTimer('SendMovementByCharID')
            try:
                gpcs.CoreServiceCall.__sendNotifyCount__['MovementNotification'] += 1
                self.ForwardNotifyDown(macho.MovementNotification(destination=macho.MachoAddress(broadcastID=None, idtype='charid', narrowcast=[charid]), payload=data))

            finally:
                callTimer.Done()





